﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using SchoolProject2012.Areas.Eleve.Models;

using SchoolProject2012.Functions;

namespace SchoolProject2012.Areas.Eleve.Controllers
{
    public class ResultController : Controller
    {
        private EleveSchoolProjectBddEntities db = new EleveSchoolProjectBddEntities();
        //
        // GET: /Eleve/Result/
        // Affiche la liste des modules
        [Authorize(Roles = "Admin, Eleve, Delegue, BDE")]
        public ActionResult Index(string langue)
        {
            System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo(Field.getLanguage(langue));
            System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo(Field.getLanguage(langue));
            ViewBag.langue = langue;
            try
            {
                string login = Session["login"].ToString();
                var classe = db.ELEVE.SingleOrDefault(x => x.LOGINPERS == login).ELEVECLASS.Single(c => c.CLASSE.ANNEECLASSE == Utils.getCurrentYearForClass());
                var module = db.MODULE.Where(x => x.CLASSE.LIBCLASSE == classe.CLASSE.LIBCLASSE).ToList();
                return View(module);
            }
            catch
            {
                return View("error");
            }
        }

        // GET: /Eleve/Result/Notes/uml
        // Affiche les notes d'un module
        [Authorize(Roles = "Admin, Eleve, Delegue, BDE")]
        public ActionResult Notes(string id, string langue)
        {
            System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo(Field.getLanguage(langue));
            try
            {
                string login = Session["login"].ToString();
                var notes = db.ELEVEEVAL.Where(x => x.LOGINPERS == login && x.EVALUATION.MODULE.LIB_MOD == id).ToList();
                ViewBag.langue = langue;
                return View(notes);
            }
            catch
            {
                return View("error");
            }
        }

        // GET: /Eleve/Result/Details/2
        // Affiche le détail d'une évaluation
        [Authorize(Roles = "Admin, Eleve, Delegue, BDE")]
        public ActionResult Details(string langue, string id, int idEval)
        {
            System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo(Field.getLanguage(langue));
            try
            {
                string login = Session["login"].ToString();
                EVALUATION eval = db.EVALUATION.SingleOrDefault(x => x.IDEVAL == idEval && x.MODULE.LIB_MOD == id);
                ViewBag.langue = langue;
                return View(eval);
            }
            catch
            {
                return View("error");
            }
        }

    }
}
